package com.cunjin.grade.comtroller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cunjin.base.controller.BaseController;
import com.cunjin.grade.entity.GradeEntity;
import com.cunjin.grade.service.GradeService;

@Controller
@RequestMapping("/grade")
public class GradeComtroller extends BaseController<GradeEntity> {

	
	@Autowired
	private GradeService service;
	
		//http://localhost:8090/cunjin-dorm/grede/myqueryAll
		@RequestMapping("/myqueryAll")
		@ResponseBody
		public Map<String, Object> myqueryAll(GradeEntity entity) {
			
			Map<String, Object> all = service.queryAll();
			return all;
		}
	
	//拿到所有的班级
	@RequestMapping("/getcommoBox")
	@ResponseBody
	public List<GradeEntity> getcommoBox(GradeEntity entity) {
		
		List<GradeEntity> all = service.getcommoBox();
		return all;
	}
	
	
	/**
	 * 分页
	 * @param page
	 * @param rows
	 * @param searchName
	 * @return
	 */
	@RequestMapping("/findWithPage")
	@ResponseBody
	public Map<String, Object>  findWithPage(int page,int rows,String searchName) {
	
		Map<String, Object>  fy = service.queryByPage(page,rows,searchName);
		return fy;
	}
	
	/**
	 * 添加一个班级
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/addGrade")
	@ResponseBody
	public Map<String, Object> addGrade(GradeEntity entity) {
		
		Map<String, Object>  map = service.insert(entity);
				return map;
	}
	
	
	/**
	 * 
	 * 删除
	 * @param dles
	 * @return
	 */
	@RequestMapping("/delGrade")
	@ResponseBody
	public Map<String, Object>  delGrade(String dles) {
		
		String[] split = dles.split(",");
		Map<String, Object>  mydelete = service.deleteByids(split);
		return mydelete;
	}

	/**
	 * 更新一个班级
	 * @param entity
	 * @return
	 */
	@RequestMapping("/updateGrade")
	@ResponseBody
	public Map<String, Object>  updateGrade(GradeEntity entity) {
		
		Map<String, Object>  myupdate = service.update(entity);
		return myupdate;
	}
	
}
